<?php
	$names = getDBrow($_SESSION['username'], 'profile');
?>

<div id="navbar">
	<a href="index.php">
		<div class="navbar_logo">
			<span class="navbar_logo_holo_underline">MyBook+</span>
		</div>
	</a>	
	<!-- User Bar -->
	<a href="?profile=<?php echo $_SESSION['username']; ?>">
		<div class="navbar_userbar">
			<?php
				if (empty($names['profilepic']))
					echo '<img src="img/nouser.png" alt="Error"/>';
				else
					echo '<img src="php/userimg/thumbnail_'.$names['profilepic'].'" alt="Fehler"/>';
			?>
			<span class="navbar_userbar_name"><?php echo htmlspecialchars($_SESSION['username']); ?></span>
		</div>
	</a>
	<div class="user_search">
		<form method="GET" action="?friends=search">	
				<input type="hidden" name="friends" value="search"/>
				<input type="text" name="suche" class="search_bar" maxlength="60" placeholder="Suche"/>
				<input type="submit" value=""/>
		</form>
	</div>
	<ul class="navbar_ul">
		<a href="index.php"><li>News Stream</li></a>
		<a href="?profile=1"><li>Mein Profil</li></a>
		<a href="?message=list"><li>Nachrichten<span class="auto_msg"></span></li></a>
		<a href="?friends=list"><li>Freunde <span class="auto_invite"></span></li></a>
		<a href="?settings=1"><li>Einstellungen</li></a>
		<a href="?logout=1"><li class="navbar_ul_logout">Ausloggen</li></a>
	</ul>
</div>

<script>
	$(document).ready(function()
	{
		var userid = "<?php echo $_SESSION['userid'];?>";
		var notificationType;
		var switchFunction;
		var firstStart=1;
		function getFriendRequests()
		{
			switchFunction = 1;
			timer();
			notificationType = 1;
			$.ajax({
			type: "POST",
			url: "./php/notifications.php",
			data :{userid: userid, notificationType: notificationType},
			}).done(function( html ){
			$(".auto_invite").fadeIn("slow").text(html);
			});
		}
		function getMessage()
		{
			switchFunction = 2;
			if(firstStart == 1)
			{
				firstStart = 0;
				getFriendRequests();
			}
			else
				timer();
			notificationType = 2;
			$.ajax({
			type: "POST",
			url: "./php/notifications.php",
			data :{userid: userid, notificationType:notificationType},
			}).done(function( html ){
			$(".auto_msg").fadeIn("slow").text(html);
			});
		}
		
		getMessage();
		function timer()
		{
			if(switchFunction == 1)
				window.setTimeout(getMessage, 5000);
			else if(switchFunction == 2)
				window.setTimeout(getFriendRequests, 5000);
			
		}
	});
</script>